1100B - Build a Contest - CodeForces Solution


data structures implementation *1300

Please click on ads to support us..

Python Code:

dificuldade_max, _ = map(int, input().split())

frequencias = {}
dificuldades = list(map(int, input().split(" ")))
resultado = ""

conjunto_questoes = 0
for dificuldade in dificuldades:
    if not(dificuldade in frequencias) or frequencias[dificuldade] == 0:
        conjunto_questoes += 1
        frequencias[dificuldade] = 1

        if conjunto_questoes == dificuldade_max:
            resultado += "1"
        else:
            resultado += "0"
    else:
        resultado += "0"
        frequencias[dificuldade] += 1

    if conjunto_questoes == dificuldade_max:
        for dif in frequencias.keys():
            frequencias[dif] -= 1

            if frequencias[dif] == 0:
                conjunto_questoes -= 1

print(resultado)

C++ Code:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <functional>
#include <list>
#include <sstream>

using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define debug(a) cout<<#a<<"="<<a<<endl
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef double db;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

const int N = 1e5+10;

int a[N];
int cnt[N];
int ans[N];

void solve()
{
	int n,m;
	cin >> n >> m;
	rep(i,1,m)
		ans[i] = n;
	rep(i,1,m){
		int x;
		cin >> x;
		cnt[x]++;
		ans[cnt[x]]--;
		if(ans[cnt[x]] == 0)
			cout << 1;
		else
			cout << 0;
	}
	cout << endl;
}

int main()
{
	IOS;
	
	int t;
	t = 1;
	while(t--){
		solve();
	}

 	return 0;
}



 	   		 	  		 	 				 			 			 		


Comments

Submit
0 Comments
More Questions

406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers
120. Triangle
102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix
71. Simplify Path